<template>
  <div>
    <span>{{item.title}}</span>
    &nbsp;
    <span>{{item.price}}元</span>
    &nbsp;
    <a href="#" @click="addToCart(item)">加入购物车</a>
  </div>
</template>

<script>
import { mapMutations } from 'vuex'

export default {
  props: {
    item: {
      type: Object,
      default() {
        return {
          id: 1,
          title: '商品A',
          price: 10
        }
      }
    }
  },
  methods: {
    ...mapMutations('cart', [
      'addToCart'
    ])
  }
}
</script>